package net.xdclass.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Classname CheckUtil
 * @Description TODO
 * @Date 2022/4/7 14:23
 * @Created by sunhao
 */
public class CheckUtil {

  /**
   * 邮箱正则
   */
  private static final Pattern MAIL_PATTERN = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");

  /**
   * 手机号正则，暂时未用
   */
  private static final Pattern PHONE_PATTERN = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");


  /**
   * 身份证号正则
   */
  private static final Pattern CARD_PATTERN = Pattern.compile("/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/");

  /**
   * @param email
   * @return
   */
  public static  boolean isEmail(String email) {
    if (null == email || "".equals(email)) {
      return false;
    }
    Matcher m = MAIL_PATTERN.matcher(email);
    return m.matches();
  }

  /**
   * @param phone
   * @return
   */
  public static boolean isPhone(String phone) {
    if (null == phone || "".equals(phone)) {
      return false;
    }
    Matcher m = PHONE_PATTERN.matcher(phone);
    return m.matches();
  }

  /**
   * @param cardId
   * @return
   */
  public static boolean isCardId(String cardId) {
    if (null == cardId || "".equals(cardId)) {
      return false;
    }
    Matcher m = CARD_PATTERN.matcher(cardId);
    return m.matches();
  }
}
